import type {
    JcxFormSchema as FormSchema,
    JcxFormProps,
} from '@/components/effects/ui';

import type {ComponentType} from './component';

import {setupJcxForm, useJcxForm as useForm, z} from '@/components/effects/ui';
import {$t} from '@/locales/effects';

setupJcxForm<ComponentType>({
    config: {
        modelPropNameMap: {
            Upload: 'fileList',
            CheckboxGroup: 'model-value',
        },
    },
    defineRules: {
        required: (value, _params, ctx) => {
            if (value === undefined || value === null || value.length === 0) {
                return $t('ui.formRules.required', [ctx.label]);
            }
            return true;
        },
        selectRequired: (value, _params, ctx) => {
            if (value === undefined || value === null) {
                return $t('ui.formRules.selectRequired', [ctx.label]);
            }
            return true;
        },
    },
});

const useJcxForm = useForm<ComponentType>;

export {useJcxForm, z};

export type JcxFormSchema = FormSchema<ComponentType>;
export type {JcxFormProps};
